package com.zjitc.service.impl;

import com.zjitc.common.ServerResponse;
import com.zjitc.dao.ProductDao;
import com.zjitc.model.Product;
import com.zjitc.service.ProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Create by IntelliJ IDEA
 *
 * @author: jsonor
 * @date-Time: 2018/5/2 15:07
 * @description:
 */
@Service
public class ProductServiceImpl implements ProductService {

  @Autowired
  private ProductDao productDao;

  @Override
  public List<Product> productAll(String type) {
    return productDao.productAll(type);
  }

  @Override
  public ServerResponse<Product> pushProduct(Product product) {
    if (product.getPname()==null){
      return ServerResponse.createError("可以添加商品");
    }
    int count = productDao.checkName(product.getPname());
    if (count==1){
      return ServerResponse.createError("商品已经存在");
    }
    productDao.pushProduct(product);
    return ServerResponse.createSuccess(product);
  }

  @Override
  public Product showProduct(Integer pid) {
    Product product  = productDao.showProduct(pid);
    return product;
  }

}
